home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 090 / cmln0885.arc / NIAL3.LTG < prev    next >
Text File  |  1986-02-27  |  2KB  |  42 lines

  1.  
  2. Nial Listing 3
  3.  
  4.  
  5. Quicksort
  6.  
  7. qsort IS OPERATION A {
  8.    IF tally A <= 1 THEN
  9.      A
  10.    ELSE
  11.      Firstpart := A < first A sublist A;
  12.      Secondpart := A match first A sublist A;
  13.      Thirdpart := A > first A sublist A;
  14.      link (qsort Firstpart) Secondpart (qsort Thirdpart)
  15.    ENDIF }
  16.  
  17. Explanation:
  18.  
  19.   IF tally A <= 1 THEN A          gives the array argument if it has only 0
  20.                                   or 1 element.
  21.  
  22.     Firstpar⌠ i≤ defineΣ t∩ bσ thσ element≤ oµ thσ arra∙ argumen⌠ ì
  23. les≤ thaε thσ firs⌠ element«  Secondpar⌠ i≤ thσ element≤ oµ thσ ì
  24. arra∙ argumen⌠ whicΦ matcΦ thσ firs⌠ element«  Thirdpar⌠ i≤ thσ ì
  25. element≤ oµ thσ arra∙ argumen⌠ whicΦ arσ greate≥ thaε the firs⌠ ì
  26. element«  linδ yield≤ aε arra∙ consistinτ oµ thσ element≤ oµ it≤ ì
  27. argument≤ linkeΣ together¼ firs⌠ thosσ les≤ thaε thσ firs⌠ ì
  28. element¼ theε thosσ whicΦ matcΦ it¼ anΣ finall∙ thosσ greate≥ ì
  29. thaε thσ firs⌠ element«  qsor⌠ i≤ invokeΣ recursivel∙ oε thσ ì
  30. Firstpar⌠ anΣ Thirdpar⌠ unti∞ the∙ arσ reduceΣ t∩ onl∙ onσ ì
  31. element«   Thσ sorteΣ arra∙ i≤ displayeΣ b∙ omittinτ ß semicoloε ì
  32. froφ thσ expressioε linδ (qsor⌠ Firstpart⌐ Secondpar⌠ (qsor⌠ ì
  33. Thirdpart)« Q'Nia∞ ha≤ ß sor⌠ primitive¼ s∩ thi≤ qsor⌠ operatioε ì
  34. i≤ no⌠ needed bu⌠ i≤ provideΣ t∩ illustratσ recursion.
  35.  
  36.     Timσ fo≥ aε arra∙ consistinτ oµ 10░ element≤ wa≤ 4▓ secì
  37. usinτ thσ abovσ qsor⌠ operation anΣ 1.┤ sec usinτ thσ sor⌠ ì
  38. predefineΣ operatioε oµ versioε 3.04« Iε versioε 3.0╢ anΣ ì
  39. following¼ sor⌠ i≤ t∩ bσ ß predefineΣ transformer¼ anΣ it≤ ì
  40. performancσ shoulΣ bσ improved.
  41.  
  42.